<?php
class Bd{
	
	private $host;
	private $user;
	private $senha;
	private $bd;

	public function __construct($host,$user,$senha,$bd) {
		$this->host  = $host;
		$this->user  = $user;
		$this->senha = $senha;
		$this->bd    = $bd;
	}
	
	public function connect() {
		mysql_connect($this->host,$this->user,$this->senha);
		mysql_select_db($this->bd);
	}
	
	public function insert($tabela,$campos,$values) {
		$sql = "INSERT INTO $tabela($campos) VALUES($values)";		
		mysql_query($sql);
	}
	
	public function update($tabela,$campos,$id) {
		$sql = "UPDATE $tabela SET $campos WHERE id=$id";
		mysql_query($sql);
	}
	
	public function delete($tabela,$id) {
		$sql = "DELETE FROM $tabela WHERE ID=$id";
		mysql_query($sql);
	}
	
	public function select($colunas, $tabela, $where="") {
		$sql = "SELECT $colunas FROM $tabela $where";
		$res = mysql_query($sql);
		$ret = array();
		if (mysql_num_rows ($res) > 0) {
			for($i=0; $i< mysql_num_rows($res); $i++) {
				$ret [] = mysql_fetch_array($res);
			}
		}
		return $ret;
	}
	
	function getId($tabela,$id) {
		$sql = 	"SELECT * FROM $tabela WHERE ID=$id";
		$res = mysql_query($sql);
		$ret = array();
		if (mysql_num_rows($res)==1) {
			$ret =mysql_fetch_array($res);
		}
		return $ret;
	}
	
	
}
?>